package com.aaa.mk.controller;

import com.aaa.mk.entity.Advertise;
import com.aaa.mk.service.AdvertiseService;
import com.aaa.common.util.Result;
import com.aaa.common.util.ResultStatus;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 广告位(Advertise)表控制层
 *
 * @author han qu
 * @since 2021-02-21 21:44:22
 */
@RestController
@RequestMapping("advertise")
@ApiOperation("advertise控制器")
public class AdvertiseController {
    /**
     * 服务对象
     */
    @Resource
    private AdvertiseService advertiseService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("单个对象查询")
    public Result selectOne(Integer id) {
        return new Result(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.advertiseService.queryById(id));
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @return 对象列表
     */
    @PostMapping("queryAll")
    public Result queryAll(Integer pageNo, Integer pageSize, @RequestBody Advertise advertise) {
        return new Result(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.advertiseService.queryAll(pageNo, pageSize, advertise));
    }

    /**
     * 新增数据
     *
     * @param advertise 实例对象
     * @return 实例对象
     */
    @PostMapping("insert")
    public Result insert(@RequestBody Advertise advertise) {
        return new Result(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.advertiseService.insert(advertise));
    }

    /**
     * 修改数据
     *
     * @param advertise 实例对象
     * @return 实例对象
     */
    @PutMapping("update")
    public Result update(@RequestBody Advertise advertise) {
        return new Result(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.advertiseService.update(advertise));
    }

    /**
     * 通过主键删除数据
     *
     * @param advertiseId 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteById")
    public Result deleteById(Integer advertiseId) {
        return new Result(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.advertiseService.deleteById(advertiseId));
    }
}